USE master
GO

IF EXISTS (SELECT [name] FROM [master].[sys].[databases] 
			   WHERE [name] = N'wcfSyncSamplesDb')
	BEGIN
		DROP DATABASE wcfSyncSamplesDb
	END

CREATE DATABASE wcfSyncSamplesDb
GO

USE wcfSyncSamplesDb
GO

CREATE SCHEMA Sales
GO

------------------------------------
--
-- Create tables for the Synchronization Services samples.
--
CREATE TABLE wcfSyncSamplesDb.Sales.Customer(
	CustomerId uniqueidentifier NOT NULL PRIMARY KEY DEFAULT NEWID(), 
	CustomerName nvarchar(100) NOT NULL,
	SalesPerson nvarchar(100) NOT NULL,
	CustomerType nvarchar(100) NOT NULL)
GO

CREATE TABLE wcfSyncSamplesDb.Sales.CustomerContact(
	CustomerId uniqueidentifier NOT NULL,
	PhoneNumber nvarchar(100) NOT NULL,
	PhoneType nvarchar(100) NOT NULL,
	CONSTRAINT PK_CustomerContact PRIMARY KEY (CustomerId, PhoneType))
GO

------------------------------------
--
-- Create FOREIGN KEY constraints between some of the tables.
--
ALTER TABLE wcfSyncSamplesDb.Sales.CustomerContact
ADD CONSTRAINT FK_CustomerContact_Customer FOREIGN KEY (CustomerId)
	REFERENCES wcfSyncSamplesDb.Sales.Customer (CustomerId)
GO


